home *** CD-ROM | disk | FTP | other *** search
- /*
- * Palette List Application
- */
-
- #include <event.h>
- #include <inits.h>
- #include <list.h>
- #include <memory.h>
- #include <menu.h>
- #include <packages.h>
- #include <quickdraw.h>
- #include <resource.h>
- #include <segment.h>
- #include <toolutil.h>
- #include <window.h>
-
- #define MENUBAR 256
- #define WINDOW 256
- #define ICON 256
- #define LDEF 256
- #define GRABBER 256
-
- #define WIDTH 26
- #define HEIGHT 22
- #define ROWS 10
- #define COLUMNS 2
-
- #define POINT(thePt) *(long *)(&thePt)
-
- WindowPtr palette;
-
- main()
- {
- MacInit();
- MenuInit();
- PaleInit();
- for (;;)
- EventDoOne();
- }
-
- MacInit()
- {
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0l);
- FlushEvents(everyEvent, 0);
- InitCursor();
- }
-
- MenuInit()
- {
- SetMenuBar(GetNewMBar(MENUBAR));
- DrawMenuBar();
- }
-
- pascal void IconListDef(lMessage, lSelect, lRect, lCell, lDataOffset, lDataLen, lHandle)
- int lMessage;
- int lSelect;
- Rect *lRect;
- long lCell;
- int lDataOffset;
- int lDataLen;
- ListHandle lHandle;
- {
- char tag;
- BitMap iconBits;
-
- BlockMove(lRect, &iconBits.bounds, (long) sizeof(Rect));
- switch (lMessage)
- {
- case lInitMsg:
- break;
-
- case lDrawMsg:
- if (lDataLen)
- {
- tag = *(char *) (*lHandle)->cells;
- HLock((*lHandle)->cells);
- iconBits.baseAddr = *(*lHandle)->cells + lDataOffset;
- iconBits.rowBytes = 4;
- CopyBits(&iconBits, &thePort->portBits, lRect, lRect, srcCopy, 0l);
- *(char *) (*lHandle)->cells = tag;
- }
- else
- EraseRect(lRect);
- if (!*(char *) &lSelect)
- break;
-
- case lHiliteMsg:
- iconBits.bounds.right--; iconBits.bounds.bottom--;
- InvertRect(&iconBits.bounds);
- break;
-
- case lCloseMsg:
- break;
- }
- }
-
- PaleInit()
- {
- Handle theLDEF;
- Rect theView;
- Rect theBounds;
- int scroll;
- Point theSize;
- ListHandle theList;
- Cell theCell;
- int id;
- Handle theIcon;
-
- palette = GetNewWindow(WINDOW, 0l, -1l);
-
- theLDEF = GetResource('LDEF', LDEF);
- *(long *) (*theLDEF + 2) = (long) &IconListDef;
-
- SetRect(&theBounds, 0, 0, COLUMNS, ROWS);
- BlockMove(&palette->portRect, &theView, (long) sizeof(Rect));
- if (scroll = (theView.bottom - theView.top) / HEIGHT < ROWS)
- theView.right -= 15;
- SetPt(&theSize, WIDTH, HEIGHT);
- theList = LNew(&theView, &theBounds, POINT(theSize), LDEF, palette, FALSE, FALSE, FALSE, scroll ? TRUE : FALSE);
- SetWRefCon(palette, theList);
- (*theList)->selFlags = lOnlyOne;
-
- for (id = 0; id < COLUMNS * ROWS; id++)
- {
- SetPt(&theCell, id % COLUMNS, id / COLUMNS);
- HLock(theIcon = GetIcon(id + ICON));
- LSetCell(*theIcon, 128, POINT(theCell), theList);
- HUnlock(theIcon);
- }
-
- SetPt(&theCell, 0, 0);
- LSetSelect(TRUE, POINT(theCell), theList);
-
- LDoDraw(TRUE, theList);
- ShowWindow(palette);
- }
-
- EventDoOne()
- {
- EventRecord theEvent;
- WindowPtr theWindow;
-
- if (GetNextEvent(everyEvent, &theEvent))
- {
- switch (theEvent.what)
- {
- case mouseDown:
- switch (FindWindow(POINT(theEvent.where), &theWindow))
- {
- case inMenuBar:
- if (MenuSelect(POINT(theEvent.where)))
- ExitToShell();
- break;
-
- case inContent:
- if (theEvent.modifiers & optionKey)
- {
- SetCursor(*GetCursor(GRABBER));
- LActivate(FALSE, GetWRefCon(palette));
- DragWindow(palette, POINT(theEvent.where), &screenBits.bounds);
- LActivate(TRUE, GetWRefCon(palette));
- InitCursor();
- }
- else
- {
- SetPort(palette);
- GlobalToLocal(&theEvent.where);
- LClick(POINT(theEvent.where), theEvent.modifiers, GetWRefCon(palette));
- }
- break;
- }
- break;
-
- case updateEvt:
- BeginUpdate(palette);
- LUpdate(palette->visRgn, GetWRefCon(palette));
- EndUpdate(palette);
- break;
-
- case activateEvt:
- LActivate(theEvent.modifiers & activeFlag ? TRUE : FALSE, GetWRefCon(palette));
- break;
- }
- }
- }
-